package view;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JLabel;

import model.Square;

public class SquareRep extends JLabel {

	private final Square square;
	public static final int WIDTH = 40;
	public static final int HEIGHT = 40;
	private static final int PELLET_DIAMETER = 4;

	public SquareRep(final Square square) {
		this.square = square;
		setOpaque(true);
	}

	@Override protected void paintComponent(final Graphics g) {
		final Graphics scratchGraphics = g.create();
		//TODO: Replace this with logic to draw the icon, once we move away from colors.
		square.getIcon().paintIcon(this, scratchGraphics, 0, 0);
		if (this.square.hasPellet()) {
			final int x = (WIDTH - PELLET_DIAMETER) / 2;
			final int y = (HEIGHT - PELLET_DIAMETER) / 2;
			scratchGraphics.setColor(Color.YELLOW);
			scratchGraphics.fillOval(x, y, PELLET_DIAMETER, PELLET_DIAMETER);
			scratchGraphics.setColor(Color.BLACK);
			scratchGraphics.drawOval(x, y, PELLET_DIAMETER, PELLET_DIAMETER);
			scratchGraphics.fillOval(x, HEIGHT - PELLET_DIAMETER - 1, PELLET_DIAMETER,
					PELLET_DIAMETER);
		}
	}

	public Square getSquare() {
		return square;
	}

}
